<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>建设施工合同列表</title>
        <%@ include file="../res.jsp"%>
        <style>
            .download:link {
            color:	#666666;
            text-decoration:underline;
            }
            .download:visited {
            color:#0000FF;
            text-decoration:none;
            }
            .download:hover {
            color:#7700BB;
            text-decoration:none;
            }
            .download:active {
            color:#D200D2;
            text-decoration:none;
            }
        </style>
    </head>
    <body>
        <form class="layui-form" action="">
            <blockquote class="layui-elem-quote news_search">
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <input type="text" id="inputQuery" style="width: 450px;" lay-verify="required" placeholder="请输入建设单位/施工单位/监理单位/工程名称" autocomplete="off" class="layui-input">
                    </div>
                    <a class="layui-btn search_btn" data-type="reload" id="btnQuery"><i class="layui-icon">&#xe615;</i>搜索</a>
                </div>
                <div class="layui-inline">
                    <a class="layui-btn layui-btn-normal newsAdd_btn" onclick="openForm('${ctx}/itemreportpre/vw-add.do', '新增合同', 600, 300)"><i class="layui-icon"></i>合同新增</a>
                </div>
            </blockquote>
            <table id="tableList" lay-filter="tableList"></table>
        </form>
        <form action="" method="post" enctype="multipart/form-data" id="fileForm" style="display: none">
             <input type="text" name ="pkId" id="pkId"/>
             <input type = "file" name = "file" id = "file" onchange = "fileFormSub();"/>
        </form>

        <script src="/plugins/jquery/jquery-1.9.1.min.js"></script>
        <script type="text/html" id="deleteBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detail"><i class="layui-icon">&#xe63c;</i>详情</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon"></i>删除</a>
            <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="uploading" id="up"><i class="layui-icon">&#xe67c;</i>上传报价单</a>
        </script>
        <script>
            layui.use(['form','table'], function(){
                var $ = layui.$, form = layui.form, table = layui.table;
                var colums = [{field: 'customerName', title: '建设单位', width:150, fixed: true}
                    ,{field: 'itemName', title: '施工单位', width:150, fixed: true}
                    ,{field: 'itemState', title: '监理单位', width:150, fixed: true}
                    ,{field: 'reportUserName', title: '工程名称', width:100, fixed: true}
                    ,{field: 'reportTime', title: '工程地点', width:180, fixed: true}
                    ,{field: 'approveUserName', title: '开工日期', width:100}
                    ,{field: 'approveTime', title: '竣工日期', width:180}
                    ,{field: 'approveTime', title: '合同金额', width:180}
                    ,{field: 'approveTime', title: '支付方式', width:180}
                    ,{field: 'approveTime', title: '合同签订日期', width:180}
                    ,{field: 'approveTime', title: '建设单位联系人', width:180}
                    ,{field: 'approveTime', title: '建设单位联系电话', width:180}
                    ,{field: 'approveTime', title: '施工单位联系人', width:180}
                    ,{field: 'approveTime', title: '施工单位联系电话', width:180}
                    ,{field: 'approveTime', title: '监理单位联系人', width:180}
                    ,{field: 'approveTime', title: '监理单位联系电话', width:180}
                    ,{field: 'approveTime', title: '合同管理编号', width:180}
                    ,{field: 'approveTime', title: '合同附件（JPG、PDF等）', width:180}
                    ,{fixed: 'right', title: '操作',toolbar: '#deleteBar', width:150}];
                table.render({
                    elem: '#tableList'
                    ,url: '${ctx}/construct/data_list'
                    ,method : 'post'
                    ,page: true
                    ,limits: [10,15,20,30,50]
                    ,limit: 15
                    ,cols: [colums]
                    ,id: 'tableList'
                });
                //监听工具条
                table.on('tool(tableList)', function(obj){
                    var data = obj.data;
                    if(obj.event === 'del'){
                        layer.confirm('确定删除?', function(index){
                            ajaxExec('${ctx}/itemreportpre/del.do', {pkId : data.pkId}, function(){
                                layer.msg('项目报备删除成功！', {icon: 6, time: 2000});
                                refreshDataList();
                            }, function(retInfo){
                                layer.msg('项目报备删除失败，' + retInfo.msg, {icon: 5, time: 2000});
                            });
                            layer.close(index);
                        });
                    } else if(obj.event === 'check'){
                        openForm('${ctx}/itemreportpre/vw-check.do?pkId='+ data.pkId, "项目报备审核", 600, 400);
                    } else if(obj.event === 'detail'){
                        openForm('${ctx}/itemreportpre/vw-detail.do?pkId='+ data.pkId+'&itemId='+data.itemId, "报备信息详情", 900, 500);
                    } else if(obj.event === 'change'){
                        openForm('${ctx}/itemreportpre/vw-change.do?pkId='+ data.pkId, "更换业务员", 600, 400);
                    } else if(obj.event === 'uploading'){
                        $("#pkId").val(data.itemId);
                        $("#file").click();
                    }
                });

                //监听下拉列表框
                form.on('select(setStateQuery)', function(data) {
                    $('#btnQuery').click();
                });
                //查询按钮功能
                 var active = {
                    reload: function() {
                        var ctlQuery = $('#inputQuery');
                        var selectState = $('#itemStateQuery');
                        //执行重载
                        table.reload('tableList', {
                            page: {
                                curr: 1
                            }
                            ,where: {
                                queryValue: ctlQuery.val()
                            }
                        });
                    }
                };
                $('#btnQuery').on('click', function() {
                    var type = $(this).data('type');
                    active[type] ? active[type].call(this) : '';
                });
            });
            function fileFormSub(){
                if($("#file").val() != ""){
                    var index = layer.load();
                    var form = new FormData(document.getElementById("fileForm"));
                    $.ajax({
                        url : "${ctx}/quotation/upload.do",
                        type : "post",
                        data : form,
                        processData : false,
                        contentType : false,
                        success : function(data) {
                            layer.close(index);
                            if(data.code == 1){
                                $("#file").val("");
                                layer.msg(data.msg ,{icon: 6, time: 2000});
                            }else{
                                layer.msg(data.msg ,{icon: 5, time: 2000});
                            }
                        }
                    });
                }
            };
        </script>
    </body>
</html>